/**
 * @author Ucar Sahin
 *
 * 26.05.2011
 * UserLogInController.java
 * 
 */

package at.fhv.easyDietWeb.server.controller.useCase;

import at.fhv.easyDietWeb.server.controller.DatabaseController;
import at.fhv.easyDietWeb.shared.db.masterData.User;
import at.fhv.easyDietWeb.shared.exception.database.MissingSearchKeyException;
import at.fhv.easyDietWeb.shared.exception.database.NoSearchResultException;
import at.fhv.easyDietWeb.shared.exception.useCase.InvalidLoginException;

/**
 * a controller to control the login process of a user
 * @author Stephan
 * 
 */
public class UserLogInController
{

	/**
	 * Search for the user with this parameters
	 * 
	 * @param name
	 * @param password
	 * @return the User if the input is valid
	 * @throws InvalidLoginException
	 *             if the combination of the parameters does not exists
	 */
	public User getUser(String name, String password)
			throws InvalidLoginException
	{
		try
		{
			return DatabaseController.getInstance().getUser(name, password);
		} 
		catch (NoSearchResultException exc)
		{
			throw new InvalidLoginException();
		}
		catch (MissingSearchKeyException exc)
		{
			throw new InvalidLoginException();
		}
	}
}
